package com.zf.multilang.controller;

import com.zf.multilang.entity.ErrorInfo;
import com.zf.multilang.entity.UserInfo;
import com.zf.multilang.utils.MessageUtils;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.web.bind.annotation.*;

/**
 * 测试获取多语言信息·
 */
@RestController
@RequestMapping("/msg")
public class MessageController {
/*    {
        "title": "<script>alert(1)</script>",
            "content": "<p>安全内容<img src=x onerror=alert(2)></p>"
    }*/
    @GetMapping("/getUserInfo")
    public UserInfo getUserInfo(@Parameter(name = "title", description = "标题") @RequestParam(name = "title",defaultValue = "<script>alert(1)</script>") String title,
                                @Parameter(name = "input", description = "用户名") @RequestParam(name = "input",defaultValue = "<p>安全内容<img src=x onerror=alert(2)></p>") String input) {
        UserInfo res = new UserInfo();
        String message = MessageUtils.getMessage("login.zhangsan", new Object[]{"好人"}, "默认没找到，{0}");
        res.setUsername(message);
        res.setTitle(title);
        res.setOthers(input);
        return res;
    }

    @GetMapping("/getErrorInfo")
    public ErrorInfo getErrorInfo() {
        ErrorInfo res = new ErrorInfo();
        String message = MessageUtils.getMessage("error.10001", new Object[]{"666"});
        res.setMsg(message);
        return res;
    }

/*    {
        "username": "st< 用户名字ring",
            "title": "<script>alert(1)</script>",
            "others": "<p>安全内容<img src=x onerror=alert(2)></p>"
    }*/
    @PostMapping("/postInfo")
    public UserInfo postInfo(@RequestBody UserInfo userInfo) {
        UserInfo res = new UserInfo();

        return userInfo;
    }
}
